﻿Imports PTIC_Util
Imports System.Windows.Forms
Imports PTIC_GestionBDD
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Collections.Specialized
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Windows.Data
Imports System.Windows.Input
Imports OMANE.Common.UI
Imports System.Windows

Namespace ViewModels
    Public Class ViewModelSegSelection
        Inherits ViewModelCommand
        Implements IViewModelTabSection

        Private m_model As ModelTauxGarantis

#Region "Constructeurs"
        Public Sub New(ByVal Model As ModelTauxGarantis, ByVal DisplayName As String, ByVal Command As ICommand)
            MyBase.New(DisplayName, Command)
            m_model = Model
            AddHandler m_model.Segmentation.SegmentationRetenueChanged, AddressOf SegmentationRetenueChanged
        End Sub
        Public Sub New()
        End Sub
#End Region

#Region "Propriétés"
        Public Property Icone As String Implements Common.UI.IViewModelTabSection.Icone
        Public Property Title As String Implements Common.UI.IViewModelTabSection.Title
        Public Property IsClosable As Boolean Implements IViewModelTabSection.IsClosable

        Public ReadOnly Property isSegmentationVisible As Visibility
            Get
                If m_model.Segmentation.Retenue.Count = 0 Then
                    Return Visibility.Hidden
                Else
                    Return Visibility.Visible
                End If
            End Get
        End Property
        Public Sub SegmentationRetenueChanged(ByVal sender As Object, ByVal e As EventArgs)
            OnPropertyChanged("isSegmentationVisible")
        End Sub

        Public ReadOnly Property Segmentation As Segmentation
            Get
                Return m_model.Segmentation
            End Get
        End Property
        Public ReadOnly Property TraitReqSegmentation As RequeteBDD
            Get
                If m_model.ListeTraitements.TraitReqSegmentation.EtatCalcul_DataTable <> ValueEtatCalcul.A_JOUR Then
                    m_model.ListeTraitements.TraitReqSegmentation.Calculer_DataTable()
                End If
                Return m_model.ListeTraitements.TraitReqSegmentation
            End Get
        End Property

        Public ReadOnly Property SegmentsPossiblesNonRetenus() As ObservableDictionary(Of String, Correspondance)
            Get
                Return m_model.Segmentation.PossibleNonRetenue
            End Get
        End Property
        Public ReadOnly Property SegmentsRetenus() As ObservableDictionary(Of String, Correspondance)
            Get
                Return m_model.Segmentation.Retenue
            End Get
        End Property

        ''' <summary>
        ''' Méthode exécutée suite à une opération de glisser/déposer
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        ''' <remarks></remarks>
        Public Sub ajouteSegRetenue(ByVal sender As Object, ByVal e As System.Windows.DragEventArgs)
            Dim lSegAajouter As List(Of Correspondance) = New List(Of Correspondance)
            lSegAajouter.Add(e.Data.GetData(GetType(KeyValuePair(Of String, Correspondance))).Value)
            m_model.Segmentation.modifSegRetenue(lSegAajouter, PTIC_GestionBDD.operationCollection.ADD)
            m_model.Segmentation.modifSegPossibleNonRetenue(lSegAajouter, PTIC_GestionBDD.operationCollection.REMOVE)
            m_model.ListeTraitements.TraitReqSegmentation.Calculer_DataTable()
        End Sub
        Public Sub ajouteSegPossibleNonRetenue(ByVal sender As Object, ByVal e As System.Windows.DragEventArgs)
            Dim lSegAajouter As List(Of Correspondance) = New List(Of Correspondance)
            lSegAajouter.Add(e.Data.GetData(GetType(KeyValuePair(Of String, Correspondance))).Value)
            m_model.Segmentation.modifSegPossibleNonRetenue(lSegAajouter, PTIC_GestionBDD.operationCollection.ADD)
            m_model.Segmentation.modifSegRetenue(lSegAajouter, PTIC_GestionBDD.operationCollection.REMOVE)
            m_model.ListeTraitements.TraitReqSegmentation.Calculer_DataTable()
        End Sub

#End Region

    End Class
End Namespace
